package com.sbs.demo.common;

import lombok.Getter;

/**
 * Business Service Exception
 *
 * @author luwenmin
 */
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 2359767995161832954L;

    @Getter
    private final ResultCode resultCode;

    @Getter
    private final Integer code;

    @Getter
    private final String msg;

    public ServiceException(ResultCode resultCode) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public ServiceException(ResultCode resultCode, String msg) {
        super(msg);
        this.resultCode = resultCode;
        this.code = resultCode.getCode();
        this.msg = msg;
    }

    public ServiceException(String msg) {
        super(msg);
        this.resultCode = ResultCode.INTERNAL_SERVER_ERROR;
        this.code = resultCode.getCode();
        this.msg = msg;
    }

    public ServiceException(String msg, Throwable cause) {
        super(msg, cause);
        this.resultCode = ResultCode.INTERNAL_SERVER_ERROR;
        this.code = ResultCode.INTERNAL_SERVER_ERROR.getCode();
        this.msg = ResultCode.INTERNAL_SERVER_ERROR.getMsg();
    }

}
